package com.way.filemanager.online;

import hwdroid.dialog.AlertDialog;
import hwdroid.dialog.Dialog;
import hwdroid.dialog.DialogInterface;
import hwdroid.util.DialogUtils;
import hwdroid.widget.ActionBar.ActionBarView;
import hwdroid.widget.ActionBar.ActionBarView.OnRightWidgetItemClick2;
import hwdroid.widget.FooterBar.FooterBarButton;
import hwdroid.widget.FooterBar.FooterBarMenu;
import hwdroid.widget.FooterBar.FooterBarType.OnFooterItemClick;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.kanbox.api.Constant;
import com.kanbox.api.DownloadFileStatus;
import com.kanbox.api.Kanbox;
import com.kanbox.api.KanboxException;
import com.kanbox.api.RequestListener;
import com.kanbox.api.Token;
import com.kanbox.api.UploadFileStatus;
import com.way.filemanager.FileManagerAppFrame;
import com.way.filemanager.R;
import com.way.filemanager.fragment.PushSharePreference;
import com.way.filemanager.fragment.activity2frag_if;
import com.way.filemanager.model.FileSystemObject;
import com.way.filemanager.navigation.MyFileManager;
import com.way.filemanager.navigation.MyFileManager.FileListener;
import com.way.filemanager.navigation.NavigationListFragmant.SelectMode;
import com.way.filemanager.navigation.Utils;
import com.way.filemanager.ui.dialogs.CustomProgressDialog;
import com.way.filemanager.ui.dialogs.RefreshDialog;
import com.way.filemanager.ui.policy.IntentsActionPolicy;
import com.way.filemanager.util.AndroidHelper;
import com.way.filemanager.util.CommonFunc;
import com.way.filemanager.util.CommonIdDef;
import com.way.filemanager.util.ConnectionHelper;
import com.way.filemanager.util.FileHelper;
import com.way.filemanager.util.ScrollOverListView;
import com.way.filemanager.util.ScrollOverListView.OnScrollOverListener;

public class FileListFragment extends Fragment implements activity2frag_if {

	private static final String TAG = "FileListFragment";

	private static final int REQUEST_CODE_LOGIN = 100;

	private static final int REQUEST_CONNECT_NETWORK = 101;

	public static final String REDIRECT_URI = "https://www.kanbox.com";

	// BugID:110153:this id and secret is for non-yunos system
	public static final String CLIENT_ID = "ef5702a1e972938a003b9621acb2aeff";

	public static final String CLIENT_SECRET = "d55745622d516d5ac51f730ec4da8426";

	private static String DOWNLOAD_DIR = Environment
			.getExternalStorageDirectory().getPath() + "/filemanager/cache/";


	private Button loginButton;

	private LinearLayout loginLayout;

	private ImageView loginPicture;


	private ScrollOverListView mListView;

	private FileListAdapter mAdapter;

	private List<OnlineFileInfo> fileInfoList;

	private MRequestListener mRequestListener;

	private DownloadFileListener mDownloadFileListener;

	private UploadFileListener mUploadFileListener;

	private OnlineFilelistManager mFilelistManager;

	private String mCurrentPath;

	private Activity mActivity;

	private FooterBarMenu mFooterBarMenu;

	private FooterBarButton mFooterBarButton;

	private LinearLayout mTitle;

	private int mCategorySubtypeMode;

	private RelativeLayout mFileListLayout;

	private EditText mkdirEditText;

	private CustomProgressDialog mProgressDialog;

	private int last_progress_type = 0;

	private RefreshDialog mRefreshDialog;

	private String dstDownloadFile;

	private static OnlineFileInfo[] PressFileInfo;

	private static OnlineFileInfo selectFileInfo;

	private OnlineFileInfo parentFileInfo;

	private boolean isLongPress = false;

	private LinearLayout mfootbar_menu_id;

	private boolean flagUpload = false;

	private SelectMode mSelectMode;

	private LinkedList<File> mLocalFiles;

	private LinkedList<File> listLocalfile = new LinkedList<File>();

	private String mlocalBasePath;

	private String mlocalRelativePath;

	private String monlieRelativePath;

	private int num_empty_dir = 0;

	private LinkedList<OnlineFileInfo> downloadList = new LinkedList<OnlineFileInfo>();

	private LinkedList<OnlineFileInfo> workList = new LinkedList<OnlineFileInfo>();

	private LinkedList<OnlineFileInfo> thumbnailList = new LinkedList<OnlineFileInfo>();

	private boolean flag_download = false;

	private int select_progress = 0;

	private PushSharePreference downloadPreference;

	private PushSharePreference thumbnailPreference;

	// private RefreshableView refreshableView;
	private int dialog_progress = 0;

	private boolean loginStatus = false;

	private boolean flag_account_changed = false;

	private boolean flag_copy_cut = true;

	private boolean resume_from_network = false;

	// BugID:103938:not show dialog again when user choose mobile network to
	// download
	// or upload
	private boolean flag_use_mobilenetwork = false;

	private String dstPathString = null;

	private AlertDialog dd = null;

	// BugID:104186:add empty wording
	private TextView online_subtypes_no_item;

	// BugID:104755:show current directory in bread crumbs
	private HorizontalScrollView mTagScroll;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		flag_download = false;
		flag_account_changed = false;
		flag_use_mobilenetwork = false;
		mActivity = getActivity();
		downloadPreference = new PushSharePreference(mActivity, "download");
		thumbnailPreference = new PushSharePreference(mActivity, "thumbnail");
		// DOWNLOAD_DIR = mActivity.getExternalCacheDir().getPath() + "/";
		File f = new File(DOWNLOAD_DIR);
		if (!f.exists()) {
			Log.d(TAG, "dowload dir not exists,mkdirs");
			f.mkdirs();
		}
		f = new File(DOWNLOAD_DIR + ".thumb");
		if (!f.exists()) {
			Log.d(TAG, "thumbnail dir not exists,mkdirs");
			f.mkdirs();
		}
		// BugID:103760:fix crash bug when press back in login page
		if (mCurrentPath == null) {
			mCurrentPath = "/";
		}
		// BugID:99830:fix FragmentList size is 0 bug after change language
		((FileManagerAppFrame) mActivity).setFragmentMap(2, this);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.d(TAG, "onCreateView---------------------------");
		loadToken();
		resume_from_network = false;
		View view = inflater.inflate(R.layout.file_list, container, false);
		loginLayout = (LinearLayout) view.findViewById(R.id.login_view);
		loginPicture = (ImageView) view.findViewById(R.id.login_picture);
		loginButton = (Button) view.findViewById(R.id.login_button);
		// BugID:104186:add empty wording
		online_subtypes_no_item = (TextView) view
				.findViewById(R.id.online_subtypes_no_item_id);
		loginButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!ConnectionHelper.hasNetwork(mActivity)) {
					showAlertDialog(mActivity);
				} else {// goto oauth webview to get token
						// get login status if account is login,use havana
						// interface,else goto system login ui
					getOauth();
				}

			}
		});
		loginLayout.setVisibility(View.INVISIBLE);
		mFileListLayout = (RelativeLayout) view
				.findViewById(R.id.filefrag_list);
		mFileListLayout.setVisibility(View.INVISIBLE);
	
		// refreshableView = (RefreshableView)
		// view.findViewById(R.id.refreshable_view);
		// refreshableView.setOnRefreshListener(new PullToRefreshListener() {
		//
		// @Override public void onRefresh() { try {
		// getFileListFromKanbox(mCurrentPath);
		// Log.d(TAG,"onRefresh--------------------------"); Thread.sleep(3000);
		// } catch (InterruptedException e) { e.printStackTrace(); }
		// refreshableView.finishRefreshing(); } }, 0);
		 

		mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
		// initNetWork();
		loginStatus = false;
		return view;
	}

	void initNetWork() {
		loadToken();
		mFilelistManager = new OnlineFilelistManager(mActivity);
		mFilelistManager.startNormal(CommonIdDef.CATEGORY_ITEM_ID_ALL);

		mListView = (ScrollOverListView) mFileListLayout
				.findViewById(R.id.filelist_listview);
		mAdapter = new FileListAdapter(mActivity, mFilelistManager);
		mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
		mListView.setAdapter(mAdapter);

		fileInfoList = new ArrayList<OnlineFileInfo>();
		if (mRequestListener == null) {
			mRequestListener = new MRequestListener();
		}
		mDownloadFileListener = new DownloadFileListener();
		mUploadFileListener = new UploadFileListener();
		Log.d(TAG, "huachao:initNetWork mCurrentPath is " + mCurrentPath);
		if (mCurrentPath == null) {
			mCurrentPath = "/";
		}
		updateCrumbs();
		// getFileListFromKanbox(mCurrentPath);

		mListView.setOnItemClickListener(mOnItemClickListener);
		mListView.setOnItemLongClickListener(mOnItemLongClickListener);
		mListView.setOnScrollOverListener(mOnScrollOverListener);
		mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
		initFootButton();

	}

	/**
	 * get oauth token
	 */
	private void getOauth() {
		Kanbox.getOauth(mActivity, CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		Log.d(TAG, "onActivityResult  login requestCode is " + requestCode
				+ ",resultCode is " + resultCode + ",data is " + data);

		if (requestCode == REQUEST_CODE_LOGIN) {
			if (resultCode == -1) {
				loginLayout.setVisibility(View.INVISIBLE);
				mFileListLayout.setVisibility(View.VISIBLE);
				getOauth();
			} else {
				Log.d(TAG, "onActivityResult  login resultCode is "
						+ resultCode);
			}

		} else if (requestCode == REQUEST_CONNECT_NETWORK) {
			if (resultCode == -1) {
				loginLayout.setVisibility(View.INVISIBLE);
				mFileListLayout.setVisibility(View.VISIBLE);
				getOauth();
			} else {
				loginLayout.setVisibility(View.VISIBLE);
				mFileListLayout.setVisibility(View.INVISIBLE);
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	void updateCrumbs() {
		mTitle = (LinearLayout) mFileListLayout
				.findViewById(R.id.dir_container);
		mTitle.removeAllViews();
		// BugID:104755:show current directory in bread crumbs
		mTagScroll = (HorizontalScrollView) mFileListLayout
				.findViewById(R.id.horizontalScrollView1);

		LinearLayout ItemMain = (LinearLayout) LayoutInflater.from(mActivity)
				.inflate(R.layout.crumbs_item, null);
		ItemMain.setBackgroundResource(R.drawable.aui_crumb_bg_main);
		ItemMain.setClickable(true);

		TextView titleMain = (TextView) ItemMain.findViewById(R.id.dir_name);
		titleMain.setText(mActivity.getString(R.string.OnlineFiles));
		mTitle.addView(ItemMain);

		ItemMain.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				getFileListFromKanbox("/");
				mCurrentPath = "/";
			}
		});

		if (!TextUtils.isEmpty(mCurrentPath)) {
			String[] names = mCurrentPath.split("/");
			Log.d(TAG, "init name length is " + names.length);
			for (int i = 1; i < names.length; i++) {
				Log.d(TAG, "init name is " + names[i]);

				LinearLayout ItemSub = (LinearLayout) LayoutInflater.from(
						mActivity).inflate(R.layout.crumbs_item, null);
				ItemSub.setBackgroundResource(R.drawable.aui_crumb_bg_sub);
				ItemSub.setClickable(true);
				TextView titlesub = (TextView) ItemSub
						.findViewById(R.id.dir_name);
				titlesub.setText(names[i]);
				LinearLayout.LayoutParams margin = new LinearLayout.LayoutParams(
						LinearLayout.LayoutParams.WRAP_CONTENT,
						LinearLayout.LayoutParams.MATCH_PARENT);
				margin.setMargins((int) (-1 * AndroidHelper.convertDpToPixel(
						mActivity, 10)), 0, 0, 0);
				mTitle.addView(ItemSub, margin);
				names[i] = names[i - 1] + "/" + names[i];
				final String ppString = names[i];
				Log.d(TAG, "init ppString is " + ppString);
				ItemSub.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						getFileListFromKanbox(ppString);
						mCurrentPath = ppString;
						Log.d(TAG, "init goto path is " + ppString);
					}
				});
			}
			// BugID:104755:show current directory in bread crumbs
			mHandler.removeCallbacks(mTagScrollRun);
			mHandler.post(mTagScrollRun);
		}

	}

	OnScrollOverListener mOnScrollOverListener = new OnScrollOverListener() {

		@Override
		public boolean onListViewTopAndPullDown(MotionEvent event, int delta) {
			return false;
		}

		@Override
		public boolean onListViewBottomAndPullUp(MotionEvent event, int delta) {
			return false;
		}

		@Override
		public boolean onMotionDown(MotionEvent ev) {
			return false;
		}

		@Override
		public boolean onMotionMove(MotionEvent ev, int delta) {
			return false;
		}

		@Override
		public boolean onMotionUp(MotionEvent ev) {
			return false;
		}

	};

	OnItemClickListener mOnItemClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> adapterview, View view,
				int position, long l) {
			// BugID:109508:not response when click "kanbox support"
			if (position >= fileInfoList.size()) {
				return;
			}
			OnlineFileInfo item = fileInfoList.get(position);
			String fullpath = item.mFullPath;
			Log.d(TAG, "onItemClick fullpath is" + fullpath
					+ ",mCurrentPath is " + mCurrentPath
					+ "mCategorySubtypeMode is " + mCategorySubtypeMode
					+ "item.mIsFolder is " + item.mIsFolder
					+ ",mCategorySubtypeMode is " + mCategorySubtypeMode
					+ "currentStatus is " + RefreshableView.currentStatus);
			/*
			 * if(RefreshableView.currentStatus !=
			 * RefreshableView.STATUS_REFRESH_FINISHED){ Log.d(TAG,
			 * "onItemClick currentStatus  is not finished, return -------------------"
			 * ); return; }
			 */
			if (mCategorySubtypeMode == CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL) {

				if (item.mIsFolder) {// is folder ,goto its subdir
					int networkType = ConnectionHelper
							.getNetworkType(mActivity);
					if (networkType == -1) {// no network dialog
						showAlertDialog(mActivity);
					}
					getFileListFromKanbox(fullpath);
					mCurrentPath = fullpath;

				} else {// not folder,download it then open it
					if (isDownloaded(item.mFullPath)) {

						if (downloadPreference != null) {
							dstDownloadFile = downloadPreference
									.getStringValueByKey(item.mFullPath);
						}
						File f = new File(dstDownloadFile);
						if (f.exists() && f.isFile()) {
							FileSystemObject fileObj = FileHelper
									.createFileSystemObject(f);
							IntentsActionPolicy.openFileSystemObject(mActivity,
									fileObj, false, null, null);
						}

					} else {
						dstDownloadFile = DOWNLOAD_DIR + item.mFullPath;
						Log.d(TAG, "onItemClick,download it to default path "
								+ dstDownloadFile);
						dialog_progress = 0;
						// BugID:102861 clear download list
						downloadList.clear();
						downloadList.add(item);
						// PressFileInfo = new OnlineFileInfo[1];
						// PressFileInfo[0] = item;
						// showProgressDialog(R.string.downloading,
						// item.mFileSize, item.mFullPath);
						downloadFile(fullpath, DOWNLOAD_DIR + mCurrentPath,
								item.mfileName, downloadList.size());
					}

				}
			} else {
				SelectItemClick(view, view.getId());
			}

		}

	};

	OnItemLongClickListener mOnItemLongClickListener = new OnItemLongClickListener() {

		@Override
		public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
				int arg2, long arg3) {
			Log.v(TAG, "onItemClick long  id is " + arg1.getId()
					+ ",mCategorySubtypeMode is " + mCategorySubtypeMode
					+ "currentStatus is " + RefreshableView.currentStatus);
			/*
			 * if(RefreshableView.currentStatus !=
			 * RefreshableView.STATUS_REFRESH_FINISHED){ Log.d(TAG,
			 * "onItemClick long currentStatus  is not finished, return -------------------"
			 * ); return false; }
			 */
			if (mCategorySubtypeMode == CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL) {
				StartItemLongPressClick(arg1.getId());
			}
			// return false;
			return true;
		}

	};

	void StartItemLongPressClick(int id) {
		// BugID:109508:not response when click "kanbox support"
		if (id < 0) {
			return;
		}
		final OnlineFileInfo info = fileInfoList.get(id);
		selectFileInfo = info;

		Log.d(TAG, "StartItemLongPressClick  info is " + info.mFullPath
				+ ",mCurrentPath is " + mCurrentPath + ",filename is "
				+ info.mfileName + "isLongPress is " + isLongPress);
		AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
		builder.setItems(R.array.onlinefile_longpress_item,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						isLongPress = true;
						String[] items = mActivity.getResources()
								.getStringArray(
										R.array.onlinefile_longpress_item);
						if (items[which].equalsIgnoreCase(mActivity
								.getResources().getString(
										R.string.actions_menu_rename))) {

							LayoutInflater factory = LayoutInflater
									.from(mActivity);
							final View textEntryView = factory.inflate(
									R.layout.alert_dialog_text_entry_mkdir,
									null);
							mkdirEditText = (EditText) textEntryView
									.findViewById(R.id.mkdir_edit);
							mkdirEditText.setText(info.mfileName);
							// bug109831
							mkdirEditText.requestFocus();
							mkdirEditText.setSelection(0);
							AlertDialog.Builder builder = new AlertDialog.Builder(
									mActivity);
							// builder.setIconAttribute(android.R.attr.alertDialogIcon);
							final String dialogTitle = getString(
									R.string.dialog_title_rename,
									info.mfileName);
							builder.setTitle(dialogTitle);
							builder.setView(textEntryView);
							builder.setPositiveButton(R.string.ok,
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int whichButton) {
											String dirNameString = mkdirEditText
													.getText().toString();
											String newPath = mCurrentPath;
											newPath = mCurrentPath + "/"
													+ dirNameString;
											Log.d(TAG, "movefile ok edit is "
													+ dirNameString
													+ ",newPath is " + newPath);
											/* User clicked OK so do some stuff */
											dialog_progress = 0;
											PressFileInfo = new OnlineFileInfo[1];
											PressFileInfo[0] = selectFileInfo;
											moveFile(info.mFullPath, newPath);
											// getFileListFromKanbox(mCurrentPath);
										}
									});
							builder.setNegativeButton(R.string.cancel,
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											/*
											 * User clicked cancel so do some
											 * stuff
											 */
										}
									});
							Dialog dd = builder.create();
							dd.getWindow()
									.setSoftInputMode(
											WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
							dd.show();
							// DialogUtils.fromBottomToTop(dd);
							// DialogUtils.NormalCenter(dd);
						} else if (items[which].equalsIgnoreCase(mActivity
								.getResources().getString(
										R.string.actions_menu_Copy))) {
							BackToUpLevel();
							((FileManagerAppFrame) getActivity())
									.listLocalPath(copyFileListener);

							mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
							mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
							mAdapter.notifyDataSetChanged();
							AddToFootButton(
									CommonIdDef.FOOTBAR_ITEM_ID_ONLINE_PASTE_COPY,
									R.string.actions_menu_Paste,
									mOnFooterItemClick);
						} else if (items[which].equalsIgnoreCase(mActivity
								.getResources().getString(
										R.string.actions_menu_Cut))) {
							BackToUpLevel();
							((FileManagerAppFrame) getActivity())
									.listLocalPath(cutFileListener);

							mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
							mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
							mAdapter.notifyDataSetChanged();
							AddToFootButton(
									CommonIdDef.FOOTBAR_ITEM_ID_ONLINE_PASTE_CUT,
									R.string.actions_menu_Paste,
									mOnFooterItemClick);

						}
						/*
						 * case 3://TODO next version share
						 * showTextAsBarcode(info.mFullPath); break;
						 */
						else if (items[which].equalsIgnoreCase(mActivity
								.getResources().getString(
										R.string.actions_menu_Delete))) {
							AlertDialog.Builder deleteBuilder = new AlertDialog.Builder(
									mActivity);
							deleteBuilder.setPositiveButton(R.string.ok,
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int whichButton) {
											dialog_progress = 0;
											flag_copy_cut = true;
											Message msg = new Message();
											msg.what = ONLINE_DELETE_START;
											mHandler.sendMessage(msg);
										}
									});
							deleteBuilder.setNegativeButton(R.string.cancel,
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int whichButton) {
											return;
										}
									});
							// View customTitleView =
							// DialogUtils.buildCustomView(mActivity,
							// R.string.DeleteFileWarnning);
							// deleteBuilder.setCustomTitle(customTitleView);
							deleteBuilder.setTitle(R.string.DeleteFileWarnning);
							AlertDialog deleteAlertDialog = deleteBuilder
									.create();
							deleteAlertDialog.show();
							// DialogUtils.fromBottomToTop(deleteAlertDialog);
						}
					}
				});
		// View v3 = DialogUtils.buildCustomView(mActivity,
		// R.string.select_dialog);
		// builder.setCustomTitle(v3);

		builder.setNegativeButton(R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
					}
				});

		Dialog dd = builder.create();
		dd.show();
		// DialogUtils.fromBottomToTop(dd);

	}

	private void showTextAsBarcode(String text) {
		Log.i(TAG, "share text as barcode: " + text);
		if (text == null) {
			return;
		}
		Intent intent = new Intent("com.aliyun.labmode.ENCODE");
		if (!(mActivity instanceof Activity)) {
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
					| Intent.FLAG_ACTIVITY_CLEAR_TASK);
		} else {
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
		}
		intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
		intent.putExtra("ENCODE_DATA", text);
		mActivity.startActivity(intent);
	}

	private void showProgressDialog(int title, final long size, String message) {

		if (mProgressDialog != null && title != last_progress_type) {
			mProgressDialog.dismiss();
			mProgressDialog = null;
		}
		if (mProgressDialog == null) {
			mProgressDialog = CustomProgressDialog.create(getActivity(),
					getString(title));
		}
		if (TextUtils.isEmpty(message)) {// fake progress dialog ,for at this
											// time, recursing directory need
											// some
											// second
			last_progress_type = -1;
		}
		last_progress_type = title;
		if (mRefreshDialog == null) {
			// BugID:104186:use new refresh dialog to sync with system style
			mRefreshDialog = new RefreshDialog(mActivity);
		}
		Log.d(TAG, "showProgressDialog size is " + size + ",message is "
				+ message);
		// mProgressDialog.setMessage(message);
		if (size == 0) {// refresh dialog
			// BugID:104186:use new refresh dialog to sync with system style
			mRefreshDialog.show();
		} else {// progress dialog
				// mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
			mProgressDialog.setMessage(message);
			// mProgressDialog.setIconAttribute(android.R.attr.alertDialogIcon);
			// mProgressDialog.setTitle(title);
			mProgressDialog.setMax((int) size);
			mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
					getText(R.string.cancel),
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							// BugID:101951:fix cancel bug when showing progress
							// dialog
							dialog_progress = (int) size + 1;
							Kanbox.disconnectKanbox();
							StartTypeNormal();
						}
					});
			mProgressDialog.show();
		}

	}

	private void showAlertDialog(Context ctx) {
		resume_from_network = true;
		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
		builder.setPositiveButton(R.string.setting,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						Intent intent = new Intent();
						intent.setAction(Settings.ACTION_WIRELESS_SETTINGS);
						startActivityForResult(intent, REQUEST_CONNECT_NETWORK);
					}
				});
		builder.setNegativeButton(R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						loginLayout.setVisibility(View.VISIBLE);
						mFileListLayout.setVisibility(View.INVISIBLE);
					}
				});
		// View customTitleView = DialogUtils.buildCustomView(ctx,
		// R.string.nonetwork_tips);
		// builder.setCustomTitle(customTitleView);
		builder.setTitle(R.string.nonetwork_tips);
		dd = builder.create();
		dd.show();
	}

	void initFootButton() {
		mFooterBarMenu = new FooterBarMenu(mActivity);

		if (mFooterBarMenu != null) {
			Log.v(TAG, "mFooterBarMenu:" + mFooterBarMenu);
			mFooterBarMenu.setOnFooterItemClick(mOnFooterItemClick);
			mfootbar_menu_id = (LinearLayout) mFileListLayout
					.findViewById(R.id.footbar_menu_id);
			mfootbar_menu_id.addView(mFooterBarMenu);

			RefreshFootMenu();
		}
	}

	void ClearFootMenu() {
		if (mFooterBarMenu != null) {
			mFooterBarMenu.clear();
		}
		if (mFooterBarButton != null) {
			mFooterBarButton.clear();
		}
		mfootbar_menu_id = (LinearLayout) mFileListLayout
				.findViewById(R.id.footbar_menu_id);
		mfootbar_menu_id.setVisibility(View.INVISIBLE);
		mfootbar_menu_id.removeAllViews();

	}

	void RefreshFootMenu() {
		mSelectMode = ((FileManagerAppFrame) mActivity).getSelectedMode();
		if (mSelectMode == SelectMode.copy || mSelectMode == SelectMode.cut) {
			mLocalFiles = ((FileManagerAppFrame) mActivity).getSelectedFiles();
			if (mLocalFiles != null) {
				if (mSelectMode == SelectMode.cut) {
					flag_copy_cut = false;
				} else if (mSelectMode == SelectMode.copy) {
					flag_copy_cut = true;
				}
				File file = new File(mLocalFiles.get(0).getAbsolutePath());
				mlocalBasePath = file.getParent();
				if (mLocalFiles != null && mLocalFiles.size() > 0) {
					mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
					mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
					mAdapter.notifyDataSetChanged();
					AddToFootButton(CommonIdDef.FOOTBAR_ITEM_ID_UPLOAD,
							R.string.upload, mOnFooterItemClick);
					((FileManagerAppFrame) mActivity).setCrossSelectedMode();
					return;
				}
			}
		}
		if (mFooterBarMenu != null) {
			ClearFootMenu();
			mfootbar_menu_id = (LinearLayout) mFileListLayout
					.findViewById(R.id.footbar_menu_id);
			mfootbar_menu_id.setVisibility(View.VISIBLE);
			mfootbar_menu_id.addView(mFooterBarMenu);
			mFooterBarMenu.addItem(
					CommonIdDef.FOOTBAR_ITEM_ID_REFRESH,
					mActivity.getResources().getText(
							R.string.actions_menu_refresh),
					mActivity.getResources().getDrawable(
							R.drawable.ic_renovate_normal));
			mFooterBarMenu.addItem(CommonIdDef.FOOTBAR_ITEM_ID_COPY, mActivity
					.getResources().getText(R.string.actions_menu_Copy),
					mActivity.getResources().getDrawable(R.drawable.copy_menu));
			mFooterBarMenu
					.addItem(
							CommonIdDef.FOOTBAR_ITEM_ID_DELETE,
							mActivity.getResources().getText(
									R.string.actions_menu_Delete),
							mActivity.getResources().getDrawable(
									R.drawable.delete_menu));
			mFooterBarMenu
					.addItem(
							CommonIdDef.FOOTBAR_ITEM_ID_CUT,
							mActivity.getResources().getText(
									R.string.actions_menu_Cut),
							mActivity
									.getResources()
									.getDrawable(
											R.drawable.hw_footerbar_item_more_icon_normal));

			mFooterBarMenu.addItem(
					CommonIdDef.FOOTBAR_ITEM_ID_MKDIR,
					mActivity.getResources().getText(
							R.string.actions_menu_NewDir),
					mActivity.getResources().getDrawable(
							R.drawable.hw_footerbar_item_more_icon_normal));

			mFooterBarMenu.setPrimaryItemCount(3);
			mFooterBarMenu.updateItems();
		}

	}

	void AddToFootButton(int FuncId, int FuncString, OnFooterItemClick m) {
		ClearFootMenu();
		if (mFooterBarButton == null)
			mFooterBarButton = new FooterBarButton(mActivity);

		mfootbar_menu_id = (LinearLayout) mFileListLayout
				.findViewById(R.id.footbar_menu_id);
		mfootbar_menu_id.setVisibility(View.VISIBLE);
		mfootbar_menu_id.removeAllViews();
		mfootbar_menu_id.addView(mFooterBarButton);

		mFooterBarButton.setOnFooterItemClick(m);
		mFooterBarButton.addItem(CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_CANCEL,
				mActivity.getResources().getText(R.string.cancel));
		mFooterBarButton.addItem(FuncId,
				mActivity.getResources().getText(FuncString));

		// mFooterBarButton.setItemTextColor(FuncId, Color.GRAY);
		if ((mCategorySubtypeMode == CommonIdDef.CATEGORY_SUBTYPE_MODE_CUT)
				|| (mCategorySubtypeMode == CommonIdDef.CATEGORY_SUBTYPE_MODE_COPY)
				|| (mCategorySubtypeMode == CommonIdDef.CATEGORY_SUBTYPE_MODE_DELETE)) {
			mFooterBarButton.setItemEnable(FuncId, false);
		} else {
			mFooterBarButton.setItemTextColor(FuncId, mActivity.getResources()
					.getColor(R.color.button_text_color_ok));
		}

		mFooterBarButton.updateItems();
		mFooterBarButton.setClickable(false);

	}

	void disableFooterBarMenu() {
		// disable copy,delete,cut button when filelist size is 0
		if (mFooterBarMenu != null) {
			mFooterBarMenu.setItemEnable(CommonIdDef.FOOTBAR_ITEM_ID_COPY,
					false);
			mFooterBarMenu.setItemEnable(CommonIdDef.FOOTBAR_ITEM_ID_DELETE,
					false);
			mFooterBarMenu
					.setItemEnable(CommonIdDef.FOOTBAR_ITEM_ID_CUT, false);
		}
	}

	void enableFooterBarMenu() {
		// enable copy,delete,cut button when filelist size is not 0
		if (mFooterBarMenu != null) {
			mFooterBarMenu
					.setItemEnable(CommonIdDef.FOOTBAR_ITEM_ID_COPY, true);
			mFooterBarMenu.setItemEnable(CommonIdDef.FOOTBAR_ITEM_ID_DELETE,
					true);
			mFooterBarMenu.setItemEnable(CommonIdDef.FOOTBAR_ITEM_ID_CUT, true);
		}
	}

	void SelectItemClick(View view, int id) {

		OnlineFileInfo info = fileInfoList.get(id);
		fileInfoList.get(id).mSelected = !info.mSelected;

		// ((DrawableText2ItemView)view).setEnabled(info.mSelected);
		view.setEnabled(info.mSelected);
		mAdapter.notifyDataSetChanged();
		int lcount = mFilelistManager.GetSelectedCount();
		if (info.mSelected) {
			mFilelistManager.SelectedAdd();
			if (mFilelistManager.GetWorkingFileCount() == mFilelistManager
					.GetSelectedCount()) {
				setAllSelectBox(true);
			}
		} else {
			mFilelistManager.SelectedDec();
			setAllSelectBox(false);
		}
		Log.v(TAG,
				"mFilelistManager.GetSelectedCount():"
						+ mFilelistManager.GetSelectedCount());
		if (!((lcount > 0) && (mFilelistManager.GetSelectedCount() > 0))) {
			if (mFilelistManager.GetSelectedCount() > 0) {
				if (mCategorySubtypeMode == CommonIdDef.CATEGORY_SUBTYPE_MODE_DELETE)
					mFooterBarButton.setItemTextColor(getFootButtonId(),
							Color.RED);
				else
					mFooterBarButton.setItemTextColor(
							getFootButtonId(),
							mActivity.getResources().getColor(
									R.color.button_text_color_ok));
				mFooterBarButton.setItemEnable(getFootButtonId(), true);
			} else {
				if (mCategorySubtypeMode == CommonIdDef.CATEGORY_SUBTYPE_MODE_DELETE)
					mFooterBarButton.setItemTextColor(getFootButtonId(),
							Color.GRAY);
				else {
					mFooterBarButton.setItemTextColor(getFootButtonId(),
							Color.GRAY);
				}
				mFooterBarButton.setItemEnable(getFootButtonId(), false);
			}
			mFooterBarButton.updateItems();
		}
		if (mActivity.getActionBar().getCustomView() instanceof ActionBarView) {
			ActionBarView mbarview = (ActionBarView) (mActivity.getActionBar()
					.getCustomView());
			mbarview.setTitle(mActivity.getResources().getQuantityString(
					R.plurals.numberOfSelected,
					mFilelistManager.GetSelectedCount(),
					mFilelistManager.GetSelectedCount()));
		}
	}

	void RefreshSelected() {
		Log.d(TAG, "RefreshSelected mFilelistManager.GetSelectedCount is  "
				+ mFilelistManager.GetSelectedCount());
		if (mFilelistManager.GetSelectedCount() > 0) {
			// mFooterBarButton.setItemTextColor(getFootButtonId(), Color.RED);
			if (getFootButtonId() == CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_DELETE)
				mFooterBarButton.setItemTextColor(getFootButtonId(), Color.RED);
			else
				mFooterBarButton.setItemTextColor(getFootButtonId(), mActivity
						.getResources().getColor(R.color.button_text_color_ok));
			mFooterBarButton.setItemEnable(getFootButtonId(), true);
			// mFooterBarButton.setClickable(true);
		} else {
			// mFooterBarButton.setItemTextColor(getFootButtonId(), Color.GRAY);
			mFooterBarButton.setItemTextColor(getFootButtonId(), Color.GRAY);
			mFooterBarButton.setItemEnable(getFootButtonId(), false);
			// mFooterBarButton.setClickable(false);
		}
		mFooterBarButton.updateItems();

		ActionBarView mbarview = (ActionBarView) (mActivity.getActionBar()
				.getCustomView());
		mbarview.setTitle(mActivity.getResources().getQuantityString(
				R.plurals.numberOfSelected,
				mFilelistManager.GetSelectedCount(),
				mFilelistManager.GetSelectedCount()));
	}

	int getFootButtonId() {
		int id = 0;
		switch (mCategorySubtypeMode) {
		case CommonIdDef.CATEGORY_SUBTYPE_MODE_COPY:
			id = CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_COPY;
			break;
		case CommonIdDef.CATEGORY_SUBTYPE_MODE_DELETE:
			id = CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_DELETE;
			break;
		case CommonIdDef.CATEGORY_SUBTYPE_MODE_CUT:
			id = CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_CUT;
			break;

		}
		return id;
	}

	OnFooterItemClick mOnFooterItemClick = new OnFooterItemClick() {
		@Override
		public void onFooterItemClick(View view, int id) {
			Log.v(TAG, "Click FooterBarMenu Item. Id = " + id
					+ ",mCurrentPath is " + mCurrentPath + ",isLongPress is "
					+ isLongPress);
			Message msg = new Message();
			switch (id) {
			case CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_CANCEL:
				((FileManagerAppFrame) mActivity).setSelectedMode(mSelectMode);
				StartTypeNormal();
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_REFRESH:
				// judge network
				if (!ConnectionHelper.hasNetwork(mActivity)) {
					showAlertDialog(mActivity);
					break;
				}// show refresh dialog
				showProgressDialog(R.string.refreshing, 0,
						getString(R.string.refreshing));
				getFileListFromKanbox(mCurrentPath);
				CommonFunc.TA_Click(CommonFunc.OnClick_Refresh);
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_COPY:
				// copy file from online to local
				StartCopy();
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_DELETE:
				CommonFunc.TA_Click(CommonFunc.OnClick_Delete);
				StartDelete();
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_CUT:
				StartCut();
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_ONLINE_PASTE_COPY:
				flag_copy_cut = true;
				dialog_progress = 0;
				msg = new Message();
				msg.what = ONLINE_COPY_START;
				mHandler.sendMessage(msg);
				((FileManagerAppFrame) mActivity).setSelectedMode(mSelectMode);
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_ONLINE_PASTE_CUT:
				flag_copy_cut = false;
				dialog_progress = 0;
				msg = new Message();
				msg.what = ONLINE_COPY_START;
				mHandler.sendMessage(msg);
				((FileManagerAppFrame) mActivity).setSelectedMode(mSelectMode);
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_UPLOAD:
				CommonFunc.TA_Click(CommonFunc.OnClick_Upload);
				if (mLocalFiles != null && mLocalFiles.size() > 0) {
					listLocalfile = Utils.listFileForUpload(mLocalFiles);
					flagUpload = true;
					dialog_progress = 0;
					msg.what = UPLOAD_START;
					mHandler.sendMessage(msg);
					((FileManagerAppFrame) mActivity)
							.setSelectedMode(mSelectMode);
				}
				break;
			case CommonIdDef.FOOTBAR_ITEM_ID_MKDIR:
				CommonFunc.TA_Click(CommonFunc.OnClick_New);
				LayoutInflater factory = LayoutInflater.from(mActivity);
				final View textEntryView = factory.inflate(
						R.layout.alert_dialog_text_entry_mkdir, null);
				mkdirEditText = (EditText) textEntryView
						.findViewById(R.id.mkdir_edit);
				mkdirEditText.setText(R.string.unnamed_folder);
				mkdirEditText.setSelectAllOnFocus(true);

				/*
				 * mkdirEditText.setOnFocusChangeListener(new
				 * OnFocusChangeListener() {
				 * 
				 * @Override public void onFocusChange(View arg0, boolean arg1)
				 * { // TODO Auto-generated method stub
				 * ((EditText)arg0).setText(null);
				 * arg0.setOnFocusChangeListener(null); } });
				 * mkdirEditText.selectAll(); final String text =
				 * mkdirEditText.getText().toString();
				 * mkdirEditText.setSelection(TextUtils.isEmpty(text) ? 0 :
				 * text.length());
				 */
				AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
				// builder.setIconAttribute(android.R.attr.alertDialogIcon);
				builder.setTitle(R.string.input_dir_name);
				builder.setView(textEntryView);
				builder.setPositiveButton(R.string.ok,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								String dirNameString = mkdirEditText.getText()
										.toString();
								Log.d(TAG, "mkdir ok edit is " + dirNameString
										+ ",current path is " + mCurrentPath);

								if (dirNameString.indexOf("/") >= 0
										|| dirNameString.indexOf("\\") >= 0) {
									// BugID:114828:show toast when dir name
									// have Backslash
									Toast.makeText(mActivity,
											R.string.ali_dirNameEmtpy,
											Toast.LENGTH_SHORT).show();
								} else if (!TextUtils.isEmpty(dirNameString)) {
									makeDir(mCurrentPath + "/" + dirNameString);
								} else {
									// BugID:103586:show toast when dir name is
									// null
									Toast.makeText(mActivity,
											R.string.ali_dirNameEmtpy,
											Toast.LENGTH_SHORT).show();
								}

							}
						});
				builder.setNegativeButton(R.string.cancel,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {

							}
						});
				AlertDialog dd = builder.create();
				dd.getWindow().setSoftInputMode(
						WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
				dd.show();

				break;
			default:
				break;
			}
		}
	};

	void StartCopy() {
		mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_COPY;
		StartSelectView(CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_COPY,
				R.string.actions_menu_Copy, mFuncCallClick);

	}

	void StartDelete() {
		mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_DELETE;
		StartSelectView(CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_DELETE,
				R.string.actions_menu_Delete, mFuncCallClick);

	}

	void StartCut() {
		mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_CUT;
		StartSelectView(CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_CUT,
				R.string.actions_menu_Cut, mFuncCallClick);

	}

	private CheckBox mBox;

	void StartSelectView(int funcId, int FuncString, OnFooterItemClick m) {
		((FileManagerAppFrame) mActivity).SetCanViewPagerMove(false);
		ActionBar bar = mActivity.getActionBar();
		ActionBarView mView = new ActionBarView(mActivity);// (ActionBarView)bar.getCustomView();
		/*
		 * mView.showBackKey(true, new OnBackKeyItemClick() {
		 * 
		 * @Override public void onBackKeyItemClick() { BackToUpLevel(); } });
		 */
		mView.setTitle(mActivity.getResources().getQuantityString(
				R.plurals.numberOfSelected, 1, 0));
		mBox = new CheckBox(mActivity);
		// cb.setOnClickListener(mActionBarSelectCheckcb);
		// BugID:101759: response all select by click right widget
		mView.setOnRightWidgetItemClickListener2(new OnRightWidgetItemClick2() {

			@Override
			public void onRightWidgetItemClick(View arg0) {
				CheckBox box = (CheckBox) arg0;
				Log.v(TAG, "mActionBarSelectCheckcb" + box.isChecked());
				if (!box.isChecked()) {
					box.setChecked(true);
					mFilelistManager.SelectedAll();
				} else {
					box.setChecked(false);
					mFilelistManager.UnSelectedAll();
				}
				if (mAdapter != null)
					mAdapter.notifyDataSetChanged();
				RefreshSelected();
				CommonFunc.TA_Click(CommonFunc.OnClick_Delete_All);
			}

		});
		mView.addRightItem(mBox);
		// mSearchView.setOnQueryTextListener(mOnQueryTextListener);
		ClearFootMenu();
		AddToFootButton(funcId, FuncString, m);
		// for all types
		mFilelistManager.startSelect(CommonIdDef.CATEGORY_ITEM_ID_ALL);

		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
		bar.setDisplayShowTitleEnabled(false);
		bar.setDisplayShowHomeEnabled(false);
		bar.setDisplayShowCustomEnabled(true);
		bar.setCustomView(mView);
		mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_SELECTING);
		mAdapter.notifyDataSetChanged();
	}

	OnFooterItemClick mFuncCallClick = new OnFooterItemClick() {
		@Override
		public void onFooterItemClick(View view, int id) {
			PressFileInfo = mFilelistManager.GetSelectCurrentFileInfo();

			switch (id) {
			case CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_CANCEL:
				BackToUpLevel();
				break;
			case CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_COPY:

				// below is copy file from online to local
				BackToUpLevel();
				((FileManagerAppFrame) getActivity())
						.listLocalPath(copyFileListener);

				mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
				mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
				mAdapter.notifyDataSetChanged();
				AddToFootButton(CommonIdDef.FOOTBAR_ITEM_ID_ONLINE_PASTE_COPY,
						R.string.actions_menu_Paste, mOnFooterItemClick);
				break;
			case CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_DELETE:

				AlertDialog.Builder deleteBuilder = new AlertDialog.Builder(
						mActivity);
				deleteBuilder.setPositiveButton(R.string.ok,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								dialog_progress = 0;
								flag_copy_cut = true;
								Message msg = new Message();
								msg.what = ONLINE_DELETE_START;
								mHandler.sendMessage(msg);
							}
						});
				deleteBuilder.setNegativeButton(R.string.cancel,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								return;
							}
						});
				View customTitleView = DialogUtils.buildCustomView(mActivity,
						R.string.DeleteFileWarnning);
				deleteBuilder.setCustomTitle(customTitleView);

				AlertDialog deleteAlertDialog = deleteBuilder.create();
				deleteAlertDialog.show();
				// DialogUtils.fromBottomToTop(deleteAlertDialog);

				break;
			case CommonIdDef.FOOTBAR_BUTTON_ID_SHOW_CUT:

				BackToUpLevel();
				((FileManagerAppFrame) getActivity())
						.listLocalPath(cutFileListener);

				mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
				mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
				mAdapter.notifyDataSetChanged();
				AddToFootButton(CommonIdDef.FOOTBAR_ITEM_ID_ONLINE_PASTE_CUT,
						R.string.actions_menu_Paste, mOnFooterItemClick);
				break;
			}
		}
	};

	OnClickListener mActionBarSelectCheckcb = new OnClickListener() {

		@Override
		public void onClick(View v) {
			CheckBox box = (CheckBox) v;
			Log.v(TAG, "mActionBarSelectCheckcb" + box.isChecked());
			if (!box.isChecked()) {
				box.setChecked(true);
				mFilelistManager.SelectedAll();
			} else {
				box.setChecked(false);
				mFilelistManager.UnSelectedAll();
			}
			if (mAdapter != null)
				mAdapter.notifyDataSetChanged();
			RefreshSelected();

		}

	};

	public void onAttach(Activity activity) {
		// Log.d(TAG,"onAttach---------------------------");
		super.onAttach(activity);
	};

	public void onActivityCreated(Bundle savedInstanceState) {
		// Log.d(TAG,"onActivityCreated---------------------------");
		super.onActivityCreated(savedInstanceState);
	};

	@Override
	public void onStart() {
		// Log.d(TAG,"onStart---------------------------");
		super.onStart();
	}

	public void onResume() {
		super.onResume();
		Log.d(TAG,
				"onResume---------------------------resume_from_network is  "
						+ resume_from_network + "flag_account_changed is "
						+ flag_account_changed);
		if (dd != null) {
			Log.d(TAG, "onResume ---- dd not null,dismiss it ");
			dd.dismiss();
		}
		if (flag_account_changed) {
			loginLayout.setVisibility(View.VISIBLE);
			mFileListLayout.setVisibility(View.INVISIBLE);
			return;
		}
		if (resume_from_network) {
			if (!loginStatus) {
				// BugID:111311:only show login view ,not show network dialog
				// when resume
				loginLayout.setVisibility(View.VISIBLE);
				mFileListLayout.setVisibility(View.INVISIBLE);

			}
		}

	};

	@Override
	public void onPause() {
		// Log.d(TAG,"onPause---------------------------");
		super.onPause();
	}

	@Override
	public void onStop() {
		// Log.d(TAG,"onStop---------------------------");
		super.onStop();
	}

	@Override
	public void onDestroyView() {
		// Log.d(TAG,"onDestroyView---------------------------");
		super.onDestroyView();
	}

	@Override
	public void onDestroy() {
		// Log.d(TAG,"onDestroy---------------------------");
		super.onDestroy();
	}

	@Override
	public void onDetach() {
		// Log.d(TAG,"onDetach---------------------------");
		super.onDetach();
	}

	public void StartTypeNormal() {
		mFilelistManager.startNormal(CommonIdDef.CATEGORY_ITEM_ID_ALL);
		mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
		((FileManagerAppFrame) mActivity).SetCanViewPagerMove(true);
		ActionBar bar = mActivity.getActionBar();
		RefreshFootMenu();

		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		bar.setDisplayShowTitleEnabled(false);
		bar.setDisplayShowHomeEnabled(false);
		bar.setDisplayShowCustomEnabled(false);

		mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
		mAdapter.notifyDataSetChanged();
		// mmSubTypesList.setSelection(0);
	}

	public boolean BackToUpLevel() {
		if (mCategorySubtypeMode != CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL) {
			StartTypeNormal();
			return true;
		}
		return false;
	}

	FileListener copyFileListener = new FileListener() {

		@Override
		public void onFile(File file) {
			if (file != null) {
				dstPathString = file.getAbsolutePath();
				Log.d(TAG, "copy myFileListener onFile is getAbsolutePath"
						+ dstPathString + " path is " + file.getPath()
						+ ",isLongPress " + isLongPress);
				dstDownloadFile = null;
				dialog_progress = 0;
				num_empty_dir = 0;
				flag_copy_cut = true;
				select_progress = 0;
				// BugID:104753:show dialog before download
				Message msg = new Message();
				int networkType = ConnectionHelper.getNetworkType(mActivity);
				if (networkType == -1) {// no network dialog
					msg.what = SHOW_NETWORK_DIALOG;
					msg.obj = "NO_NETWORK";
				} else if (networkType != ConnectivityManager.TYPE_WIFI
						&& !flag_use_mobilenetwork) {
					// show 2/3g network tips
					msg.what = SHOW_NETWORK_DIALOG;
					msg.obj = dstPathString;
				} else {
					msg.what = DOWNLOAD_START;
					msg.obj = dstPathString;
				}
				mHandler.sendMessage(msg);

			} else {
				Log.d(TAG, "copy file is null");
			}
		}
	};

	FileListener cutFileListener = new FileListener() {

		@Override
		public void onFile(File file) {
			if (file != null) {
				dstPathString = file.getAbsolutePath();
				Log.d(TAG, "cut myFileListener onFile is getAbsolutePath"
						+ dstPathString + " path is " + file.getPath()
						+ ",isLongPress " + isLongPress);
				dstDownloadFile = null;
				dialog_progress = 0;
				num_empty_dir = 0;
				flag_copy_cut = false;
				select_progress = 0;
				// BugID:104753:show dialog before download
				Message msg = new Message();
				int networkType = ConnectionHelper.getNetworkType(mActivity);
				if (networkType == -1) {// no network dialog
					msg.what = SHOW_NETWORK_DIALOG;
					msg.obj = "NO_NETWORK";
				} else if (networkType != ConnectivityManager.TYPE_WIFI
						&& !flag_use_mobilenetwork) {
					// show 2/3g network tips
					msg.what = SHOW_NETWORK_DIALOG;
					msg.obj = dstPathString;
				} else {
					msg.what = DOWNLOAD_START;
					msg.obj = dstPathString;
				}
				mHandler.sendMessage(msg);
			} else {
				Log.d(TAG, "cut file is null");
			}

		}
	};

	private class MRequestListener implements RequestListener {

		@Override
		public void onComplete(String response, int operationType) {
			Message msg = new Message();
			Log.d(TAG, "onComplete MRequestListener type is " + operationType
					+ "response is " + response);

			switch (operationType) {
			case Constant.OP_REFRESH_TOKEN:
			case Constant.OP_GET_TOKEN:
				flag_account_changed = false;
				// BugID:110153:use new interface to get token
				// Token.getInstance().parseToken(response);
				Token.getInstance().setToken(response, null, 3600);
				saveToken(Token.getInstance());
				msg.what = HANDL_SUC;
				msg.obj = response;
				mHandler.sendMessage(msg);
				Log.d(TAG, "get token,so getFileListFrom Kanbox again type is "
						+ operationType);
				getFileListFromKanbox(mCurrentPath);
				return;
			case Constant.OP_GET_FILELIST:
				msg.what = GET_FILE_LIST;
				msg.obj = response;
				mHandler.sendMessage(msg);
				break;
			case Constant.OP_COPY:
			case Constant.OP_MOVE:
				// BugID:102991: fix copy error bug when file already exist
				try {
					JSONObject sData = new JSONObject(response);
					String status = sData.getString("status");
					Log.d(TAG, "OP_COPY OP_MOVE status is " + status
							+ ",type is " + operationType
							+ ",dialog_progress is " + dialog_progress);
					if ("error".equals(status)) {
						String code = sData.getString("errorCode");
						Message errMessage = new Message();
						if ("ERROR_PATH_EXIST".equals(code)) {
							Log.e(TAG, "OP_COPY OP_MOVE ERROR_PATH_EXIST----");
							errMessage.what = COPY_ERROR;
							mHandler.sendMessage(errMessage);
						} else if ("ERROR_PATH_NOT_EXIST".equals(code)) {
							// BugID:114828:Fix rename error
							if (operationType == Constant.OP_MOVE) {
								errMessage.what = RENAME_ERROR;
								mHandler.sendMessage(errMessage);
							}
						} else if ("ERROR_UNKNOWN".equals(code)) {
							// BugID:103665:fix rename error bug
							if (operationType == Constant.OP_MOVE) {
								errMessage.what = RENAME_ERROR;
								mHandler.sendMessage(errMessage);
							}

						}
					}

					dialog_progress++;
					if (mProgressDialog != null) {
						mProgressDialog.setProgress(dialog_progress);
					}
					if (PressFileInfo != null) {
						if (dialog_progress < PressFileInfo.length) {
							msg.what = ONLINE_COPY_START;
							msg.obj = response;
							mHandler.sendMessage(msg);
						} else if (dialog_progress == PressFileInfo.length) {
							msg.what = ONLINE_COPY_SUC;
							msg.obj = response;
							mHandler.sendMessage(msg);
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				break;
			case Constant.OP_DELETE:
				dialog_progress++;
				if (mProgressDialog != null) {
					mProgressDialog.setProgress(dialog_progress);
				}
				if (PressFileInfo != null) {
					if (dialog_progress < PressFileInfo.length) {
						msg.what = ONLINE_DELETE_START;
						msg.obj = response;
						mHandler.sendMessage(msg);
					} else if (dialog_progress == PressFileInfo.length) {
						msg.what = ONLINE_COPY_SUC;
						msg.obj = response;
						mHandler.sendMessage(msg);
					}
				}
				break;
			case Constant.OP_MAKE_DIR:
				try {
					JSONObject sData = new JSONObject(response);
					String status = sData.getString("status");
					Log.d(TAG, "onComplete MRequestListener mkdir status is "
							+ status + ",flagUpload is " + flagUpload);
					if ("ok".equals(status)) {
						if (flagUpload) {// uploading
							dialog_progress++;
							if (listLocalfile != null) {
								Log.d(TAG,
										"progress onComplete MRequestListener dialog_progress is "
												+ dialog_progress
												+ ",listLocalfile.size is "
												+ listLocalfile.size()
												+ ",response is " + response);
								if (dialog_progress < listLocalfile.size()) {
									msg.what = UPLOAD_START;
									msg.obj = response;
									mHandler.sendMessage(msg);
								} else if (dialog_progress == listLocalfile
										.size()) {
									msg.what = UPLOAD_SUC;
									msg.obj = response;
									mHandler.sendMessage(msg);
								}
							}
						} else {// not upload , just mkdir
							getFileListFromKanbox(mCurrentPath);
						}

					} else if ("error".equals(status)) {
						String code = sData.getString("errorCode");
						if ("ERROR_PATH_EXIST".equals(code)) {
							Log.e(TAG,
									"onComplete MRequestListener mkdir ERROR_PATH_EXIST----");
							msg.what = MKDIR_EXIST_ERROR;
							mHandler.sendMessage(msg);
						} else {
							// BugID:103586:show toast when dir name is
							// illegal
							Log.e(TAG,
									"onComplete MRequestListener mkdir ERROR_UNKNOWN----");
							msg.what = MKDIR_NAME_ERROR;
							mHandler.sendMessage(msg);
						}
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
				break;
			// BugID:104001:ignore download in MRequestListener
			case Constant.OP_DOWNLOAD:
				break;
			default:
				handleResponse(response);
				break;
			}

		}

		@Override
		public void onError(KanboxException error, int operationType) {
			Log.d(TAG, "onError MRequestListener  type is " + operationType);
			Message msg = new Message();
			if (operationType == Constant.OP_GET_FILELIST) {
				msg.what = GET_LIST_FAIL;
				Log.d(TAG,
						"onError MRequestListener OP_GET_FILELIST or OP_GET_TOKEN error,get or refresh token");
			} else if (operationType == Constant.OP_GET_TOKEN) {
				Log.d(TAG,
						"onError MRequestListener OP_GET_TOKEN error,get  token");
				msg.what = GET_TOKEN_FAIL;
				// BugID:105018:fix kanbox server no response bug when refresh
				// token
			} else if (operationType == Constant.OP_REFRESH_TOKEN) {
				Log.d(TAG, "onError MRequestListener OP_REFRESH_TOKEN error");
				msg.what = REFRESH_TOKEN_FAIL;
			} else {
				if (mProgressDialog != null) {
					mProgressDialog.dismiss();
				}
				if (mRefreshDialog != null) {
					mRefreshDialog.dismiss();
				}
				return;
			}
			msg.obj = error.getStatusCode() + "\n\n" + error.toString();
			mHandler.sendMessage(msg);

		}

	}

	public final static String BroadcastActionScan = "com.aliyunos.filemanager.ActionScan";

	private class DownloadFileListener implements DownloadFileStatus {

		@Override
		public void onStart(int operationType) {
			/*
			 * Message msg = new Message(); msg.what = DOWNLOAD_START; msg.obj =
			 * getString(R.string.download_start); mHandler.sendMessage(msg);
			 */
			return;

		}

		@Override
		public void onComplete(String response, int operationType) {
			Message msg = new Message();
			Log.d(TAG, "onComplete DownloadFileListener type is "
					+ operationType);
			// BugID:102861:fix open twice bug when download too much picture
			if (operationType == Constant.OP_GET_FILELIST) {
				Log.d(TAG,
						"onComplete DownloadFileListener type is OP_GET_FILELIST,return");
				return;
			}
			if (operationType == Constant.OP_GET_THUMBNAIL) {
				Log.d(TAG,
						"onComplete DownloadFileListener type is OP_GET_THUMBNAIL, ignore it");
				dialog_progress++;
				if (thumbnailList != null) {
					if (dialog_progress < thumbnailList.size()) {
						msg.what = GET_THUMBNAIL;
						msg.obj = response;
						mHandler.sendMessage(msg);
					} else if (dialog_progress == thumbnailList.size()) {
						msg.what = DOWNLOAD_SUC;
						msg.obj = response;
						mHandler.sendMessage(msg);
						String path = MyFileManager.getFm().getCurrentDir()
								.getPath();
						Uri localUri = Uri.fromFile(new File(path));
						Intent localIntent = new Intent(BroadcastActionScan,
								localUri);// "android.intent.action.MEDIA_MOUNTED"
						// localIntent.putExtra(CommonIdDef.DELETE_BY_FILEMANAGER,
						// Self);
						mActivity.sendBroadcast(localIntent);
					}
				}
				return;
			}

			dialog_progress++;
			Log.d(TAG, "onComplete DownloadFileListener  type is "
					+ operationType + ",response is " + response
					+ ",dialog_progress is " + dialog_progress);
			if (downloadList != null) {
				Log.d(TAG,
						"onComplete DownloadFileListener dialog_progress is "
								+ dialog_progress
								+ ",downloadList size is "
								+ downloadList.size()
								+ ",response is "
								+ response
								+ ",path is "
								+ MyFileManager.getFm().getCurrentDir()
										.getPath());
				if (dialog_progress < downloadList.size()) {
					msg.what = DIR_DOWNLOAD_START;
					msg.obj = response;
					mHandler.sendMessage(msg);
				} else if (dialog_progress == downloadList.size()) {
					msg.what = DOWNLOAD_SUC;
					msg.obj = response;
					mHandler.sendMessage(msg);
					String path = MyFileManager.getFm().getCurrentDir()
							.getPath();
					Uri localUri = Uri.fromFile(new File(path));
					Intent localIntent = new Intent(BroadcastActionScan,
							localUri);// "android.intent.action.MEDIA_MOUNTED"
					// localIntent.putExtra(CommonIdDef.DELETE_BY_FILEMANAGER,
					// Self);
					mActivity.sendBroadcast(localIntent);
				}
			}

			if (TextUtils.isEmpty(dstDownloadFile)) {
				Log.d(TAG,
						"download not open this file ,dstDownloadFile is null,just return ");
				return;
			}
			File f = new File(dstDownloadFile);
			if (f.isFile() && f.exists()) {
				Log.d(TAG,
						"download onComplete open dst file,isFile is "
								+ f.isFile() + ", exist is " + f.exists()
								+ "dstDownloadFile is " + dstDownloadFile);
				FileSystemObject fileObj = FileHelper.createFileSystemObject(f);
				IntentsActionPolicy.openFileSystemObject(mActivity, fileObj,
						false, null, null);
			} else {
				Log.d(TAG, "download dstDownloadFile is null");
			}

			return;

		}

		@Override
		public void onError(KanboxException error, int operationType) {
			if (operationType == Constant.OP_GET_THUMBNAIL) {
				Log.d(TAG,
						"onError DownloadFileListener type is OP_GET_THUMBNAIL, ignore it");
				return;
			}
			Log.d(TAG, "onError DownloadFileListener  type is " + operationType);
			Message msg = new Message();
			msg.what = DOWNLOAD_FAIL;
			msg.obj = error.getStatusCode() + "\n\n" + error.toString();
			mHandler.sendMessage(msg);
		}

		@Override
		public void onProgress(long currSize, int operationType) {
			if (operationType == Constant.OP_GET_THUMBNAIL) {
				Log.d(TAG,
						"onError DownloadFileListener type is OP_GET_THUMBNAIL, ignore it");
				return;
			}
			if (mProgressDialog != null) {
				// mProgressDialog.setProgress((int)currSize);
				mProgressDialog.setProgress(dialog_progress);
			}
			// Log.d(TAG,"downloading-------------- currSize is "+currSize);
		}

	}

	private void handleResponse(String response) {
		Log.d(TAG, "handleResponse   response is " + response);
		Message msg = new Message();
		try {
			JSONObject sData = new JSONObject(response);
			String status = sData.getString("status");
			if (status.equals("ok")) {
				msg.what = HANDL_SUC;
				msg.obj = response;
				mHandler.sendMessage(msg);
			} else {
				msg.what = HANDL_FAIL;
				msg.obj = response;
				mHandler.sendMessage(msg);
			}
		} catch (JSONException e) {
			msg.what = HANDL_FAIL;
			msg.obj = e.toString();
			mHandler.sendMessage(msg);
		}
	}

	private class UploadFileListener implements UploadFileStatus {

		@Override
		public void onStart(int operationType) {
			/*
			 * Message msg = new Message(); msg.what = UPLOAD_START; msg.obj =
			 * getString(R.string.upload_start); mHandler.sendMessage(msg);
			 */
		}

		@Override
		public void onComplete(String response, int operationType) {
			Message msg = new Message();
			dialog_progress++;
			if (listLocalfile != null) {
				// if(mLocalFiles!=null ){
				Log.d(TAG,
						"progress onComplete UploadFileListener dialog_progress is "
								+ dialog_progress
								+ ",listLocalfile.size is "
								+ listLocalfile.size()
								+ ",response is "
								+ response
								+ ",path is "
								+ MyFileManager.getFm().getCurrentDir()
										.getPath());
				if (dialog_progress < listLocalfile.size()) {
					msg.what = UPLOAD_START;
					msg.obj = response;
					mHandler.sendMessage(msg);
				} else if (dialog_progress == listLocalfile.size()) {
					msg.what = UPLOAD_SUC;
					msg.obj = response;
					mHandler.sendMessage(msg);
					String path = MyFileManager.getFm().getCurrentDir()
							.getPath();
					Uri localUri = Uri.fromFile(new File(path));
					Intent localIntent = new Intent(BroadcastActionScan,
							localUri);// "android.intent.action.MEDIA_MOUNTED"
					// localIntent.putExtra(CommonIdDef.DELETE_BY_FILEMANAGER,
					// Self);
					mActivity.sendBroadcast(localIntent);
				}
			}

		}

		@Override
		public void onError(KanboxException error, int operationType) {
			Log.d(TAG, "onError UploadFileListener error ,operationType is "
					+ operationType);
			Message msg = new Message();
			msg.what = UPLOAD_FAIL;
			msg.obj = error.getStatusCode() + "\n\n" + error.toString();
			mHandler.sendMessage(msg);
		}

		@Override
		public void onProgress(long currSize, int operationType) {

			if (mProgressDialog != null) {
				// mProgressDialog.setProgress((int)currSize);
				mProgressDialog.setProgress(dialog_progress);
			}
			// Log.d(TAG,"uploading-------------- currSize is "+currSize);
		}

	}

	private static final int GET_FILE_LIST = 0;

	private static final int HANDL_SUC = 1;

	private static final int HANDL_FAIL = 2;

	private static final int DOWNLOAD_START = 3;

	private static final int DOWNLOAD_PROGRESS = 4;

	private static final int DOWNLOAD_SUC = 5;

	private static final int UPLOAD_SUC = 6;

	private static final int UPLOAD_PROGRESS = 7;

	private static final int UPLOAD_START = 8;

	private static final int GET_THUMBNAIL = 9;

	private static final int GET_LIST_FAIL = 10;

	private static final int DOWNLOAD_FAIL = 11;

	private static final int UPLOAD_FAIL = 12;

	private static final int ONLINE_COPY_SUC = 13;

	private static final int ONLINE_COPY_START = 14;

	private static final int ONLINE_DELETE_START = 15;

	private static final int MKDIR_EXIST_ERROR = 16;

	private static final int GET_TOKEN_FAIL = 17;

	private static final int DIR_DOWNLOAD_START = 18;

	private static final int COPY_ERROR = 19;

	private static final int RENAME_ERROR = 20;

	private static final int MKDIR_NAME_ERROR = 21;

	private static final int SHOW_NETWORK_DIALOG = 22;

	private static final int REFRESH_TOKEN_FAIL = 23;

	@SuppressLint("HandlerLeak")
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			Log.d(TAG, "mHandler msg what is " + msg.what
					+ ",dialog_progress is " + dialog_progress
					+ ",loginStatus is " + loginStatus);

			switch (msg.what) {
			case GET_FILE_LIST:

				try {
					String jsonString = (String) msg.obj;
					JSONObject response = new JSONObject(jsonString);

					if (response.isNull("contents")) {
						/*
						 * Toast.makeText(mActivity,
						 * getString(R.string.empty_list),
						 * Toast.LENGTH_SHORT).show();
						 */
					} else {
						fileInfoList.clear();
						mFilelistManager.clearAll();
						thumbnailList.clear();
						JSONArray contents = response.getJSONArray("contents");
						Log.d(TAG,
								"------------get file list contents length is "
										+ contents.length());
						if (contents.length() == 0) {
							num_empty_dir++;
						}
						for (int i = 0; i < contents.length(); i++) {
							JSONObject item = contents.getJSONObject(i);
							String fullPath = item.getString("fullPath");
							String modificationDate = item
									.getString("modificationDate");
							long fileSize = item.getLong("fileSize");
							boolean isFolder = item.getBoolean("isFolder");
							boolean isShared = item.getBoolean("isShared");
							long creationDate = item.getLong("creationDate");
							boolean hasDownloaded = false;
							if (!isFolder) {
								hasDownloaded = isDownloaded(fullPath);
							}

							int fileType;
							String path[] = fullPath.split("/");
							String fileName = path[path.length - 1];
							String thumbnailPath = DOWNLOAD_DIR + ".thumb"
									+ fullPath;
							boolean hasThumbnailFlag = false;
							fileType = mFilelistManager.getFileType(fileName);
							if (fileType == CommonIdDef.CATEGORY_ITEM_ID_PICTURE
									&& !flag_download) {
								// when download mode,ignore thumbnail
								hasThumbnailFlag = hasThumbnail(fullPath);
							}
							Log.d(TAG, "get file name is " + fileName
									+ ",fileType is " + fileType
									+ ",hasDownloaded is " + hasDownloaded
									+ ",thumbnailPath is " + thumbnailPath
									+ ",hasThumbnailFlag is "
									+ hasThumbnailFlag);

							OnlineFileInfo fileitem = new OnlineFileInfo(
									fullPath, modificationDate, fileSize,
									isFolder, isShared, creationDate, fileName,
									CommonIdDef.CATEGORY_ITEM_ID_ALL,
									hasDownloaded, hasThumbnailFlag,
									thumbnailPath);
							// BugID:102024:use thumbnail list to download
							// thumbnail one by one
							if (fileType == CommonIdDef.CATEGORY_ITEM_ID_PICTURE
									&& !flag_download && !hasThumbnailFlag) {
								thumbnailList.add(fileitem);
							}

							if (flag_download) {
								downloadList.add(fileitem);
								OnlineFileInfo removeFileInfo = getParent(fileitem.mFullPath);
								if (removeFileInfo != null) {
									Log.d(TAG, "worklist remove parent is "
											+ removeFileInfo.mFullPath);
									workList.remove(removeFileInfo);
								}
								if (fileitem.mIsFolder) {
									Log.d(TAG,
											"workList add it, filelist is folder , get its filelist again ,"
													+ fileitem.mFullPath);
									getFileListFromKanbox(fileitem.mFullPath);
									parentFileInfo = fileitem;
									workList.add(parentFileInfo);
								}
							} else {
								fileInfoList.add(fileitem);
							}
						}
						Log.d(TAG, "workList size is " + workList.size()
								+ ",flag_download is " + flag_download
								+ "num_empty is " + num_empty_dir);
						if (flag_download && workList.size() > 0) {
							for (OnlineFileInfo f : workList) {
								Log.d(TAG, "print workList is " + f.mFullPath);
							}
							if (num_empty_dir == workList.size()) {
								Log.d(TAG,
										"num_empty_dir=workList.size, clear workList ");
								workList.clear();
							}
						}
						if (flag_download && workList.size() == 0) {
							// woklist is empty, goto download
							dialog_progress = 0;
							num_empty_dir = 0;
							Message mm = new Message();
							mm.what = DIR_DOWNLOAD_START;
							mHandler.sendMessage(mm);
						}
						Log.d(TAG,
								"thumbnailList size is " + thumbnailList.size());
						if (!flag_download && thumbnailList != null
								&& thumbnailList.size() > 0) {
							dialog_progress = 0;
							Message mm = new Message();
							mm.what = GET_THUMBNAIL;
							mHandler.sendMessage(mm);
						}
						// BugID:104531:fix online file sort bug
						mFilelistManager.sortByFullPath(fileInfoList);
						mFilelistManager.addWorkingList(fileInfoList);
						// mAdapter.setData(fileInfoList);
						Log.d(TAG, "mCurrentPath is " + mCurrentPath);
						mAdapter.notifyDataSetChanged();
						updateCrumbs();
						if (fileInfoList != null) {
							// BugID:102144 disable FooterBarMenu when size
							// is 0
							Log.d(TAG, "GET_FILE_LIST fileInfoList size is"
									+ fileInfoList.size());
							if (fileInfoList.size() == 0) {
								disableFooterBarMenu();
								// BugID:104186:add empty wording
								online_subtypes_no_item
										.setVisibility(View.VISIBLE);
								mListView.setVisibility(View.INVISIBLE);
							} else {
								enableFooterBarMenu();
								// BugID:104186:add empty wording
								online_subtypes_no_item
										.setVisibility(View.INVISIBLE);
								mListView.setVisibility(View.VISIBLE);
							}
						}
					}
					loginStatus = true;
					loginLayout.setVisibility(View.INVISIBLE);
					mFileListLayout.setVisibility(View.VISIBLE);

				} catch (JSONException e) {
					e.printStackTrace();
					loginStatus = false;
				}

				if (mProgressDialog != null) {
					mProgressDialog.dismiss();
				}
				if (mRefreshDialog != null) {
					mRefreshDialog.dismiss();
				}

				break;
			case HANDL_SUC:
				if (PressFileInfo != null
						&& dialog_progress == PressFileInfo.length) {
					dialog_progress = 0;
					if (mProgressDialog != null) {
						mProgressDialog.dismiss();
					}
					StartTypeNormal();
					getFileListFromKanbox(mCurrentPath);
				}

				break;
			case HANDL_FAIL:
				Log.d(TAG, "mhandler HANDL_FAIL---------------------------");
				loginStatus = false;
				// BugID:104001:show toast when network err
				// loginLayout.setVisibility(View.VISIBLE);
				// mFileListLayout.setVisibility(View.INVISIBLE);
				Toast.makeText(mActivity, R.string.network_error,
						Toast.LENGTH_SHORT).show();
				break;
			case DOWNLOAD_SUC:
				flag_download = false;
				select_progress = 0;
				dialog_progress = 0;
				num_empty_dir = 0;
				if (mProgressDialog != null) {
					mProgressDialog.dismiss();
				}
				if (downloadList != null
						&& dialog_progress == downloadList.size()) {
					downloadList.clear();
				}
				if (thumbnailList != null
						&& dialog_progress == thumbnailList.size()) {
					thumbnailList.clear();
				}
				Log.d(TAG, "DOWNLOAD_SUC flag_copy_cut is " + flag_copy_cut);
				if (!flag_copy_cut) {
					// this case is cut , so delete online file after
					// download
					dialog_progress = 0;
					Message mm = new Message();
					mm.what = ONLINE_DELETE_START;
					mHandler.sendMessage(mm);
					break;
				}
				StartTypeNormal();
				getFileListFromKanbox(mCurrentPath);
				break;
			case DOWNLOAD_FAIL:
				Log.d(TAG,
						"mhandler DOWNLOAD_FAIL refreshAccessToken----------------");
				flag_download = false;
				select_progress = 0;
				num_empty_dir = 0;
				dialog_progress = 0;
				if (downloadList != null) {
					downloadList.clear();
				}
				if (mProgressDialog != null) {
					mProgressDialog.dismiss();
				}
				// Toast.makeText(mActivity, R.string.network_error,
				// Toast.LENGTH_SHORT).show();
				refreshAccessToken();
				StartTypeNormal();
				// getFileListFromKanbox(mCurrentPath);
				break;
			case DOWNLOAD_PROGRESS:
				break;
			// BugID:104753:show dialog before download
			case SHOW_NETWORK_DIALOG:
				dstPathString = (String) msg.obj;
				Log.d(TAG, "mHandler SHOW_NETWORK_DIALOG dstPathString is "
						+ dstPathString);
				if ("NO_NETWORK".equals(dstPathString)) {
					showAlertDialog(mActivity);
				} else {
					AlertDialog.Builder builder = new AlertDialog.Builder(
							mActivity);
					builder.setPositiveButton(R.string.ok,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int whichButton) {
									flag_use_mobilenetwork = true;
									Message msg0 = new Message();
									msg0.what = DOWNLOAD_START;
									msg0.obj = dstPathString;
									mHandler.sendMessage(msg0);
								}
							});
					builder.setNegativeButton(R.string.cancel,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int whichButton) {
									return;
								}
							});
					builder.setTitle(R.string.download_tips);
					AlertDialog dd = builder.create();
					dd.show();
				}
				break;
			case DOWNLOAD_START:
				if (dialog_progress == 0 && select_progress == 0) {
					dstPathString = (String) msg.obj;
				}
				// showProgressDialog(R.string.downloading, 100, "");
				flag_download = true;
				Log.d(TAG,
						"----------------DOWNLOAD_START  select_progress is "
								+ select_progress + ",dialog_progress is "
								+ dialog_progress + ",dstPathString is "
								+ dstPathString);
				if (isLongPress) {// long press
					workList.clear();
					downloadList.clear();
					isLongPress = false;
					PressFileInfo = new OnlineFileInfo[1];
					PressFileInfo[0] = selectFileInfo;
					downloadList.add(selectFileInfo);
					if (mCurrentPath.equals("/")) {
						monlieRelativePath = selectFileInfo.mFullPath;
					} else if (selectFileInfo.mFullPath
							.startsWith(mCurrentPath)) {
						monlieRelativePath = selectFileInfo.mFullPath
								.substring(mCurrentPath.length());
					}
					Log.d(TAG, "longpress monlieRelativePath is "
							+ monlieRelativePath);
					if (selectFileInfo.mIsFolder) {
						// get its folder filelist
						getFileListFromKanbox(selectFileInfo.mFullPath);
						parentFileInfo = selectFileInfo;
						workList.add(parentFileInfo);
					} else {// just download it
						downloadFile(selectFileInfo.mFullPath, dstPathString,
								selectFileInfo.mfileName, downloadList.size());
					}
				} else {// by footer,not long press
					Message mm = new Message();
					if (flag_download && workList.size() == 0
							&& select_progress == PressFileInfo.length) {
						// in this case ,only select multiple file ,no
						// directory
						dialog_progress = 0;
						num_empty_dir = 0;
						mm.what = DIR_DOWNLOAD_START;
						mHandler.sendMessage(mm);
						break;
					}
					if (select_progress >= PressFileInfo.length) {
						break;
					}
					Log.d(TAG, "++++++ to local PressFileInfo.length is "
							+ PressFileInfo.length + "dst path is "
							+ dstPathString + "\n ++++++select_progress is "
							+ select_progress + ",src PressFileInfo[i] is "
							+ PressFileInfo[select_progress].mFullPath);
					if (select_progress == 0) {
						workList.clear();
						downloadList.clear();
					}
					selectFileInfo = PressFileInfo[select_progress];
					downloadList.add(selectFileInfo);
					select_progress++;
					if (mCurrentPath.equals("/")) {
						monlieRelativePath = selectFileInfo.mFullPath;
					} else if (selectFileInfo.mFullPath
							.startsWith(mCurrentPath)) {
						monlieRelativePath = selectFileInfo.mFullPath
								.substring(mCurrentPath.length());
					}
					Log.d(TAG, "++++++++++++monlieRelativePath is "
							+ monlieRelativePath);
					if (selectFileInfo.mIsFolder) {
						// get its folder filelist
						getFileListFromKanbox(selectFileInfo.mFullPath);
						parentFileInfo = selectFileInfo;
						workList.add(parentFileInfo);
					}
					mm.what = DOWNLOAD_START;
					mHandler.sendMessage(mm);

				}
				break;
			case DIR_DOWNLOAD_START:
				if (dialog_progress >= downloadList.size()) {
					Log.d(TAG, "break dialogprogress is " + dialog_progress
							+ ",downloadList.size is " + downloadList.size());
					break;
				}
				OnlineFileInfo ff = downloadList.get(dialog_progress);
				if (mCurrentPath.equals("/")) {
					monlieRelativePath = ff.mFullPath;
				} else if (ff.mFullPath.startsWith(mCurrentPath)) {
					monlieRelativePath = ff.mFullPath.substring(mCurrentPath
							.length());
				}
				Log.d(TAG, "---|||||||----DIR_DOWNLOAD_START dstPath is "
						+ dstPathString + ",file path is " + ff.mFullPath
						+ ",monlieRelativePath is " + monlieRelativePath
						+ ",dialog_progress is " + dialog_progress
						+ ",download size is " + downloadList.size());
				if (ff.mIsFolder) {
					Log.d(TAG, "is folder,just mkdir");
					makeLocalDir(dstPathString + monlieRelativePath);
					dialog_progress++;
					Message mm = new Message();
					if (dialog_progress < downloadList.size()) {
						mm.what = DIR_DOWNLOAD_START;
						mHandler.sendMessage(mm);
					} else if (dialog_progress == downloadList.size()) {
						mm.what = DOWNLOAD_SUC;
						mHandler.sendMessage(mm);
					}
				} else {
					Log.d(TAG, "is file ,download it, fullpath is "
							+ ff.mFullPath);
					downloadFile(ff.mFullPath, dstPathString,
							monlieRelativePath, downloadList.size());
				}
				flag_download = false;
				break;
			case GET_THUMBNAIL:
				// BugID:102024:use thumbnail list to download thumbnail one
				// by one
				Log.d(TAG, "-----------GET_THUMBNAIL dialog_progress is "
						+ dialog_progress + "thumbnailList size is "
						+ thumbnailList.size());
				if (dialog_progress >= thumbnailList.size()) {
					Log.d(TAG, "GET_THUMBNAIL break dialogprogress is "
							+ dialog_progress + ",thumbnailList.size is "
							+ thumbnailList.size());
					break;
				}
				OnlineFileInfo thumb = thumbnailList.get(dialog_progress);
				getThumbnailFromKanbox(thumb.mFullPath, DOWNLOAD_DIR + ".thumb"
						+ thumb.mFullPath);

				break;
			case GET_LIST_FAIL:
				Log.d(TAG,
						"mHandler getlist fail just refresh token ------------------------,msg.obj is "
								+ msg.obj);
				refreshAccessToken();
				loginStatus = false;
				break;
			case GET_TOKEN_FAIL:
				loginLayout.setVisibility(View.INVISIBLE);
				mFileListLayout.setVisibility(View.VISIBLE);
				getOauth();
				break;
			// BugID:105018:fix kanbox server no response bug when refresh
			// token
			case REFRESH_TOKEN_FAIL:
				if (mRefreshDialog != null) {
					mRefreshDialog.dismiss();
				}
				if (mProgressDialog != null) {
					mProgressDialog.dismiss();
				}
				loginLayout.setVisibility(View.VISIBLE);
				mFileListLayout.setVisibility(View.INVISIBLE);
				Toast.makeText(mActivity, R.string.network_error,
						Toast.LENGTH_SHORT).show();
				break;
			case UPLOAD_START:
				if ((listLocalfile != null) && (listLocalfile.size() > 0)) {
					File file = new File(listLocalfile.get(dialog_progress)
							.getAbsolutePath());
					if (file.getAbsolutePath().startsWith(mlocalBasePath)) {
						mlocalRelativePath = file.getAbsolutePath().substring(
								mlocalBasePath.length());
						// Log.d(TAG," List local ----------- mlocalRelativePath is "+mlocalRelativePath);
					} else {
						mlocalRelativePath = listLocalfile.get(dialog_progress)
								.getName();
					}
					if (file.isDirectory()) {
						makeDir(mCurrentPath + mlocalRelativePath);
					} else {
						uploadFile(listLocalfile.get(dialog_progress)
								.getAbsolutePath(), mCurrentPath,
								mlocalRelativePath, listLocalfile.size());
					}
					StartTypeNormal();
				}

				break;
			case UPLOAD_SUC:
				if (listLocalfile != null) {
					Log.d(TAG, "progress listLocalfile size is "
							+ listLocalfile.size() + ", dialog_progress is "
							+ dialog_progress);
				}
				if (listLocalfile != null
						&& dialog_progress == listLocalfile.size()) {
					dialog_progress = 0;
					if (mProgressDialog != null) {
						mProgressDialog.dismiss();
					}
					flagUpload = false;
					getFileListFromKanbox(mCurrentPath);
					// BugID:103188:delete local file when upload by cut
					if (!flag_copy_cut) {
						// cut file from local to online
						if (listLocalfile != null) {
							listLocalfile = Utils
									.listAllDeleteFiles(listLocalfile);
							for (File f : listLocalfile) {
								if (f.exists()) {
									Log.d(TAG, "-----upload delete it,f is "
											+ f.getPath());
									f.delete();

								}
							}
						}
					}
				}
				break;
			case UPLOAD_FAIL:
				if (mProgressDialog != null) {
					mProgressDialog.dismiss();
				}
				StartTypeNormal();
				Toast.makeText(mActivity, R.string.network_error,
						Toast.LENGTH_SHORT).show();
				refreshAccessToken();
				break;
			case ONLINE_COPY_START:
				if (isLongPress) {
					isLongPress = false;
					PressFileInfo = new OnlineFileInfo[1];
					PressFileInfo[0] = selectFileInfo;
					showProgressDialog(R.string.copying, PressFileInfo.length,
							selectFileInfo.mFullPath);
					Log.d(TAG, "progress copyFile longpress src is "
							+ selectFileInfo.mFullPath + ",dst is "
							+ mCurrentPath + "/" + selectFileInfo.mfileName);
					if (flag_copy_cut) {
						// showProgressDialog(R.string.copying,PressFileInfo.length,selectFileInfo.mFullPath);
						copyFile(selectFileInfo.mFullPath, mCurrentPath + "/"
								+ selectFileInfo.mfileName);
					} else {
						// showProgressDialog(R.string.copying,PressFileInfo.length,selectFileInfo.mFullPath);
						moveFile(selectFileInfo.mFullPath, mCurrentPath + "/"
								+ selectFileInfo.mfileName);
					}
				} else {
					if (PressFileInfo != null) {
						if (dialog_progress < PressFileInfo.length) {
							showProgressDialog(R.string.copying,
									PressFileInfo.length,
									PressFileInfo[dialog_progress].mFullPath);
							if (flag_copy_cut) {
								// showProgressDialog(R.string.copying,PressFileInfo.length,PressFileInfo[dialog_progress].mFullPath);
								copyFile(
										PressFileInfo[dialog_progress].mFullPath,
										mCurrentPath
												+ "/"
												+ PressFileInfo[dialog_progress].mfileName);
							} else {
								// showProgressDialog(R.string.copying,PressFileInfo.length,PressFileInfo[dialog_progress].mFullPath);
								moveFile(
										PressFileInfo[dialog_progress].mFullPath,
										mCurrentPath
												+ "/"
												+ PressFileInfo[dialog_progress].mfileName);
							}
						}
					}
				}
				break;
			case ONLINE_COPY_SUC:
				if (PressFileInfo != null
						&& dialog_progress == PressFileInfo.length) {
					dialog_progress = 0;
					if (mProgressDialog != null) {
						mProgressDialog.dismiss();
					}
					StartTypeNormal();
					getFileListFromKanbox(mCurrentPath);
				}
				break;
			case ONLINE_DELETE_START:
				if (isLongPress) {
					isLongPress = false;
					PressFileInfo = new OnlineFileInfo[1];
					PressFileInfo[0] = selectFileInfo;
					showProgressDialog(R.string.deleting, PressFileInfo.length,
							selectFileInfo.mFullPath);
					Log.d(TAG, "progress deleteFile online longpress src is "
							+ selectFileInfo.mFullPath + ",dst is "
							+ mCurrentPath + "/" + selectFileInfo.mfileName);
					deleteOnlineFile(selectFileInfo.mFullPath);
				} else {
					if (PressFileInfo != null) {
						if (dialog_progress < PressFileInfo.length) {
							showProgressDialog(R.string.deleting,
									PressFileInfo.length,
									PressFileInfo[dialog_progress].mFullPath);
							deleteOnlineFile(PressFileInfo[dialog_progress].mFullPath);
						}
					}
				}
				break;
			case MKDIR_EXIST_ERROR:
				Toast.makeText(mActivity, R.string.ali_dirIsExist,
						Toast.LENGTH_SHORT).show();
				break;
			case COPY_ERROR:
				Toast.makeText(mActivity, R.string.copy_error,
						Toast.LENGTH_SHORT).show();
				break;
			// BugID:103665:fix rename error bug
			case RENAME_ERROR:
				Toast.makeText(mActivity, R.string.RenameFail,
						Toast.LENGTH_SHORT).show();
				break;
			// BugID:103586:show toast when dir name is illegal
			case MKDIR_NAME_ERROR:
				Toast.makeText(mActivity, R.string.ali_dirNameEmtpy,
						Toast.LENGTH_SHORT).show();
				break;
			default:
				break;
			}
		};
	};

	public String[] StringSplit(String longString) {
		String[] sourceStrArray = longString.split(",");

		return sourceStrArray;
	}

	public void saveToken(Token token) {
		PushSharePreference sPreference = new PushSharePreference(mActivity,
				"oauth");
		sPreference.saveStringValueToSharePreferences("accecc_token",
				token.getAcceccToken());
		sPreference.saveStringValueToSharePreferences("refresh_token",
				token.getRefreshToken());
		sPreference.saveLongValueToSharePreferences("expries",
				token.getExpires());
	}

	public void loadToken() {
		PushSharePreference sPreference = new PushSharePreference(mActivity,
				"oauth");
		Token sToken = Token.getInstance();
		sToken.setAcceccToken(sPreference.getStringValueByKey("accecc_token"));
		sToken.setRefreshToken(sPreference.getStringValueByKey("refresh_token"));
		sToken.setExpires(sPreference.getLongValueByKey("expries"));
	}

	private String getUpPath(String current) {
		String upString = "/";
		if (!TextUtils.isEmpty(current)) {
			upString = current
					.substring(0, current.lastIndexOf(File.separator));
		}
		return upString;
	}

	private OnlineFileInfo getParent(String child) {
		OnlineFileInfo ret = null;
		Log.d(TAG, "getParent start is " + child);
		child = child.substring(0, child.lastIndexOf(File.separator));
		Log.d(TAG, "getParent after process  is " + child);
		if (workList != null && workList.size() > 0) {
			for (OnlineFileInfo f : workList) {
				if (f.mFullPath.equals(child)) {
					ret = f;
					break;
				}
			}
		}
		return ret;
	}

	private boolean makeLocalDir(String path) {
		Log.d(TAG, "makeLocalDir path is " + path);
		File newDir = new File(path);
		if (newDir.exists() && newDir.isDirectory()) {
			return false;
		} else {
			return new File(path).mkdirs();
		}
	}

	private boolean isDownloaded(String src) {
		boolean ret = false;
		String dst = null;
		if (downloadPreference != null) {
			dst = downloadPreference.getStringValueByKey(src);
			if (!TextUtils.isEmpty(dst)) {
				File dstFile = new File(dst);
				if (dstFile.exists()) {
					ret = true;
				} else {
					Log.d(TAG,
							"isDownloaded dstfile not exist , so remove this key ");
					downloadPreference.removeSharePreferences(dst);
				}
			}
		}
		Log.d(TAG, "isDownloaded src is " + src + ",dst is " + dst + ",ret is "
				+ ret);
		return ret;
	}

	private boolean hasThumbnail(String src) {
		boolean ret = false;
		String dst = null;
		if (thumbnailPreference != null) {
			dst = thumbnailPreference.getStringValueByKey(src);
			if (!TextUtils.isEmpty(dst)) {
				File dstFile = new File(dst);
				if (dstFile.exists()) {
					ret = true;
				} else {
					Log.d(TAG,
							"hasThumbnail dstfile not exist , so remove this key ");
					thumbnailPreference.removeSharePreferences(dst);
				}
			}
		}
		Log.d(TAG, "hasThumbnail src is " + src + ",dst is " + dst + ",ret is "
				+ ret);
		return ret;
	}

	private void getFileListFromKanbox(String mCurrentPath) {
		Log.d(TAG, "-------getFileListFromKanbox path is " + mCurrentPath);
		Kanbox.getFileList(mCurrentPath, mRequestListener);
	}

	private void getThumbnailFromKanbox(String src, String dst) {

		File file = new File(DOWNLOAD_DIR + ".thumb" + mCurrentPath);
		boolean isDir = false;
		if (!file.exists()) {
			isDir = file.mkdirs();
		}
		dstDownloadFile = null;
		Log.d(TAG, "getThumbnailFromKanbox src is " + src + ",dst is " + dst
				+ ",idDir is " + isDir);
		thumbnailPreference.saveStringValueToSharePreferences(src, dst);
		// Kanbox.getThumbnail(src,dst, "small",mDownloadFileListener );
		// Kanbox.getThumbnail(src,dst, "medium",mDownloadFileListener );
		Kanbox.getThumbnail(src, dst, "large", mDownloadFileListener);
	}

	/**
	 * refresh access_token
	 */
	private void refreshAccessToken() {
		getOauth();
	}

	/**
	 * getAccountInfo
	 */
	private void getAccountInfo() {
		Kanbox.getAccountInfo(mRequestListener);
	}

	/**
	 * moveFile
	 */
	private void moveFile(String src, String dst) {
		Log.d(TAG, "moveFile src is " + src + ", dst is " + dst);
		Kanbox.moveFile(src, dst, mRequestListener);
	}

	/**
	 * copyFile
	 */
	private void copyFile(String src, String dst) {
		Log.d(TAG, "copyFile src is " + src + ", dst is " + dst);
		Kanbox.copyFile(src, dst, mRequestListener);
	}

	/**
	 * deleteOnlineFile
	 * 
	 * @return
	 */
	private void deleteOnlineFile(String fullpath) {
		Kanbox.deleteFile(fullpath, mRequestListener);
		return;
	}

	/**
	 * makeDir
	 */
	private void makeDir(String path) {
		Log.d(TAG, "makeDir path  is " + path + ",current path is "
				+ mCurrentPath);
		Kanbox.makeDir(path, mRequestListener);
	}

	/**
	 * downloadFile
	 */

	private void downloadFile(final String src, final String dstPath,
			final String filename, final long size) {

		int networkType = ConnectionHelper.getNetworkType(mActivity);
		Log.d(TAG, "-----++++----------download src is " + src
				+ ",networkType is " + networkType + ",dst is " + dstPath
				+ ",filename is " + filename);
		if (TextUtils.isEmpty(dstPath)) {
			return;
		}
		File file = new File(dstPath);
		boolean dir_ok = false;
		if (!file.exists()) {
			dir_ok = file.mkdirs();
			Log.d(TAG,
					"download -----------dstPath not exists,mkdirs it ,result is "
							+ dir_ok);
		}

		if (networkType == -1) {// no network dialog
			showAlertDialog(mActivity);
			// BugID:103938:not show dialog again when user choose mobile
			// network to
			// download or upload
		} else if (networkType != ConnectivityManager.TYPE_WIFI
				&& !flag_use_mobilenetwork) {
			// show 2/3g network tips
			AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
			builder.setPositiveButton(R.string.ok,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							flag_use_mobilenetwork = true;
							showProgressDialog(R.string.downloading, size, src);
							downloadPreference
									.saveStringValueToSharePreferences(src,
											dstPath + "/" + filename);
							Kanbox.download(src, dstPath + "/" + filename,
									mDownloadFileListener);
						}
					});
			builder.setNegativeButton(R.string.cancel,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							return;
						}
					});
			// View customTitleView = DialogUtils.buildCustomView(mActivity,
			// R.string.download_tips);
			// builder.setCustomTitle(customTitleView);
			builder.setTitle(R.string.download_tips);
			AlertDialog dd = builder.create();
			dd.show();
			// DialogUtils.fromBottomToTop(dd);

		} else {
			showProgressDialog(R.string.downloading, size, src);
			downloadPreference.saveStringValueToSharePreferences(src, dstPath
					+ "/" + filename);
			Kanbox.download(src, dstPath + "/" + filename,
					mDownloadFileListener);
		}

	}

	/**
	 * uploadFile
	 */
	private void uploadFile(final String src, final String dstPath,
			final String filename, final long size) {

		int networkType = ConnectionHelper.getNetworkType(mActivity);
		final String onlinePathString;
		if ("/".equals(dstPath)) {
			onlinePathString = filename;
		} else {
			onlinePathString = dstPath + filename;
		}
		Log.d(TAG, "uploadFile networkType is " + networkType + ",dst is "
				+ dstPath + ",filename is " + filename + ",src is " + src
				+ ",onlinePathString " + onlinePathString);

		if (networkType == -1) {// no network dialog
			showAlertDialog(mActivity);
			// BugID:103938:not show dialog again when user choose mobile
			// network to
			// download or upload
		} else if (networkType != ConnectivityManager.TYPE_WIFI
				&& !flag_use_mobilenetwork) {
			// show network in 2/3G tips
			AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
			builder.setPositiveButton(R.string.ok,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							flag_use_mobilenetwork = true;
							showProgressDialog(R.string.uploading, size, src);
							downloadPreference
									.saveStringValueToSharePreferences(
											onlinePathString, src);
							try {
								Kanbox.upload(src, onlinePathString,
										mUploadFileListener);
							} catch (IOException e) {
								e.printStackTrace();
								Message msg = new Message();
								msg.what = UPLOAD_FAIL;
								mHandler.sendMessage(msg);
							}
						}
					});
			builder.setNegativeButton(R.string.cancel,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							return;
						}
					});
			// View customTitleView = DialogUtils.buildCustomView(mActivity,
			// R.string.upload_tips);
			// builder.setCustomTitle(customTitleView);
			builder.setTitle(R.string.upload_tips);
			AlertDialog dd = builder.create();
			dd.show();
			// DialogUtils.fromBottomToTop(dd);

		} else {
			showProgressDialog(R.string.uploading, size, src);
			downloadPreference.saveStringValueToSharePreferences(
					onlinePathString, src);
			try {
				Kanbox.upload(src, onlinePathString, mUploadFileListener);
			} catch (IOException e) {
				e.printStackTrace();
				Message msg = new Message();
				msg.what = UPLOAD_FAIL;
				mHandler.sendMessage(msg);
			}
		}
	}

	// BugID:104755:show current directory in bread crumbs
	private Runnable mTagScrollRun = new Runnable() {
		@Override
		public void run() {
			if (mTagScroll != null) {
				mTagScroll.fullScroll(View.FOCUS_RIGHT);
			}
		}
	};

	@Override
	public boolean fragOnKeyUp(int keyCode, KeyEvent event) {
		// BugID:103063:return to previous mode or up path when press back key
		Log.d(TAG, "keyCode is " + keyCode + ",mCategorySubtypeMode is"
				+ mCategorySubtypeMode);
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (mCategorySubtypeMode != CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL) {
				StartTypeNormal();
				return true;
			}
			if (mCurrentPath.equals("/")) {
				return false;
			}
			String upPath = getUpPath(mCurrentPath);
			// Log.d(TAG, "------------ upPath is " + upPath + ",current is " +
			// mCurrentPath);
			if (TextUtils.isEmpty(upPath)) {
				upPath = "/";
			}
			mCurrentPath = upPath;
			getFileListFromKanbox(upPath);
			return true;
		}
		return false;
	}

	@Override
	public boolean exit() {
		return false;
	}

	@Override
	public boolean setLoginStatus(boolean status) {
		Log.d(TAG, "setLoginStatus is " + status);
		if (status) {
			loginStatus = true;
			initNetWork();
			getFileListFromKanbox(mCurrentPath);
			loginLayout.setVisibility(View.INVISIBLE);
			mFileListLayout.setVisibility(View.VISIBLE);

		} else {
			loginStatus = false;
			loginLayout.setVisibility(View.VISIBLE);
			mFileListLayout.setVisibility(View.INVISIBLE);
		}
		return false;
	}

	@Override
	public boolean judgeUpload() {
		flag_download = false;

		loginPicture.setImageResource(R.drawable.filemanager_pictures_login);

		if (!loginStatus) {
			if (!ConnectionHelper.hasNetwork(mActivity)) {
				Log.d(TAG, "judgeUpload no network");
				showAlertDialog(mActivity);
				return false;
			}

			PushSharePreference sPreference = new PushSharePreference(
					mActivity, "oauth");
			String accessToken = sPreference
					.getStringValueByKey("accecc_token");
			String oldHavanvaID = sPreference.getStringValueByKey("havanaID");
			flag_account_changed = false;
			// Log.d(TAG, "judgeUpload not login, token is " + accessToken +
			// ",oldHavanaID is"
			// + oldHavanvaID);
			if (TextUtils.isEmpty(accessToken)) {
				// first install login,need get token,show login ui
				loginLayout.setVisibility(View.VISIBLE);
				mFileListLayout.setVisibility(View.INVISIBLE);
				return false;
			} else {
				// already have token, can't get login state ,just get file
				// list
				showProgressDialog(R.string.refreshing, 0,
						getString(R.string.refreshing));
				initNetWork();
				getFileListFromKanbox(mCurrentPath);
			}
			// return false;
		}

		mSelectMode = ((FileManagerAppFrame) mActivity).getSelectedMode();
		Log.d(TAG, "huachao:onjudgeUpload mSelectMode is " + mSelectMode
				+ ",loginStatus is " + loginStatus);
		if (mSelectMode == SelectMode.copy || mSelectMode == SelectMode.cut) {
			mLocalFiles = ((FileManagerAppFrame) mActivity).getSelectedFiles();
			// BugID:103188:delete local file when upload by cut
			if (mSelectMode == SelectMode.cut) {
				flag_copy_cut = false;
			} else if (mSelectMode == SelectMode.copy) {
				flag_copy_cut = true;
			}
			if (mLocalFiles == null) {
				Log.e(TAG, "onjudgeUpload xxxxxx mLocalFiles is null");
				return false;
			}
			File file = new File(mLocalFiles.get(0).getAbsolutePath());
			mlocalBasePath = file.getParent();

			if (mLocalFiles != null && mLocalFiles.size() > 0) {
				Log.d(TAG, "huachao:onjudgeUpload mLocalFiles size is "
						+ mLocalFiles.size() + "base path is "
						+ mLocalFiles.get(0).getPath());
				mCategorySubtypeMode = CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL;
				mAdapter.SetAdapterMode(CommonIdDef.CATEGORY_SUBTYPE_MODE_NORMAL);
				mAdapter.notifyDataSetChanged();
				AddToFootButton(CommonIdDef.FOOTBAR_ITEM_ID_UPLOAD,
						R.string.upload, mOnFooterItemClick);
				((FileManagerAppFrame) mActivity).setCrossSelectedMode();
				for (File f : mLocalFiles) {
					Log.d(TAG, "onjudgeUpload mSelected local file name is "
							+ f.getName() + ",path is " + f.getAbsolutePath()
							+ "mlocalBasePath is " + mlocalBasePath);
				}
			} else {
				Log.d(TAG, "onjudgeUpload mLocalFiles is null ");
			}
		}
		Log.d(TAG, "huachao:onjudgeUpload mLocalFiles is null ");
		return false;
	}

	// BugID:103938:clear flag of use mobile network
	public boolean setMobileFlag() {
		flag_use_mobilenetwork = false;
		Log.d(TAG, "setMobileFlag flag_use_mobilenetwork is "
				+ flag_use_mobilenetwork);
		return false;
	}

	private void setAllSelectBox(boolean isAllSelect) {
		if (mBox != null) {
			mBox.setChecked(isAllSelect);
		}
	}
}
